package org.fast.easy.messages.feign.factory;

import lombok.extern.slf4j.Slf4j;
import org.fast.easy.core.domain.result.R;
import org.fast.easy.core.domain.messages.MessagePublishDomain;
import org.fast.easy.messages.feign.service.MessagesFeignService;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import static org.fast.easy.messages.feign.constant.MessagesServiceNameConstants.MESSAGES_FEIGN_SERVICE_NAME;

/**
 * 类说明
 *
 * @author YanMing
 * @date 2024/5/15
 */
@Slf4j
@Component
public class MessagesFeignFallbackFactory implements FallbackFactory<MessagesFeignService>{
    @Override
    public MessagesFeignService create(Throwable cause) {
        log.error("{}服务调用失败:{}", MESSAGES_FEIGN_SERVICE_NAME, cause.getMessage());
        return new MessagesFeignService()
        {
            @Override
            public R<Void> publishAll(MessagePublishDomain message) {
                return R.fail("推送消息失败:" + cause.getMessage());
            }

            @Override
            public R<Void> emailCode(String email) {
                return R.fail("发送邮件验证码失败:" + cause.getMessage());
            }

            @Override
            public R<Void> smsCode(String phonenumber) {
                return R.fail("发送短信验证码失败:" + cause.getMessage());
            }
        };

    }
}
